doctype html
html
  head
    meta charset='UTF-8'
    meta http-equiv='X-UA-Compatible' content='IE=edge'
    meta name='viewport' content='width=device-width, initial-scale=1.0'
    title Self billing credit note
  body
    == SlimHelper.render('templates/credit_notes/_styles', self)

    .wrapper
      .mb-24
        h1.credit-note-title = I18n.t('credit_note.document_name')

      .mb-24.overflow-auto
        .credit-note-information-column
          table.credit-note-information-table
            tr
              td.body-1 = I18n.t('credit_note.credit_note_number')
              td.body-2 = number
            tr
              td.body-1 = I18n.t('credit_note.invoice_number')
              td.body-2 = invoice.number
            tr
              td.body-1 = I18n.t('credit_note.issue_date')
              td.body-2 = I18n.l(issuing_date, format: :default)
        .credit-note-information-column
          table.credit-note-information-table
            - if customer.metadata.displayable.any?
              - customer.metadata.displayable.order(created_at: :asc).each do |metadata|
                tr
                  td.body-1 = metadata.key
                  td.body-2 = metadata.value

      .mb-24.overflow-auto
        .billing-information-column
          .body-1 = I18n.t('credit_note.credit_from')
          .body-2 = customer.display_name
          - if customer.legal_number.present?
            .body-2 #{customer.legal_number}
          .body-2 = customer.address_line1
          .body-2 = customer.address_line2
          .body-2
            span
              = customer.zipcode
            - if customer.zipcode.present? && customer.city.present?
              span
                | , &nbsp;
            span
              = customer.city
          .body-2 = customer.state
          .body-2 = ISO3166::Country.new(customer.country)&.common_name
          .body-2 = customer.email
          - if customer.tax_identification_number.present?
            .body-2 = I18n.t('invoice.tax_identification_number', tax_identification_number: customer.tax_identification_number)

        .billing-information-column
          .body-1 = I18n.t('credit_note.credit_to')
          .body-2
            - if organization.legal_name.present?
              = organization.legal_name
            - else
              = organization.name
          - if organization.legal_number.present?
            .body-2 #{organization.legal_number}
          .body-2 = organization.address_line1
          .body-2 = organization.address_line2
          .body-2
            span
              = organization.zipcode
            - if organization.zipcode.present? && organization.city.present?
              span
                | , &nbsp;
            span
              = organization.city
          - if organization.state.present?
            .body-2 = organization.state
          .body-2 = ISO3166::Country.new(organization.country)&.common_name
          .body-2 = organization.email
          - if organization.tax_identification_number.present?
            .body-2 = I18n.t('invoice.tax_identification_number', tax_identification_number: organization.tax_identification_number)

      .mb-24
        h2.title-2.mb-8 = MoneyHelper.format(total_amount)
        .body-1
          - if credited? && refunded?
            = I18n.t('credit_note.credited_refunded_notice', issuing_date: I18n.l(issuing_date, format: :default))
          - elsif credited?
            = I18n.t('credit_note.credited_notice', issuing_date: I18n.l(issuing_date, format: :default))
          - else
            = I18n.t('credit_note.refunded_notice', issuing_date: I18n.l(issuing_date, format: :default))

      == SlimHelper.render('templates/credit_notes/_details', self)
      == SlimHelper.render('templates/credit_notes/_eu_tax_management', self)

      p.body-3.mb-24 = LineBreakHelper.break_lines(I18n.t("credit_note.self_billed.footer"))

      == SlimHelper.render('templates/credit_notes/_powered_by_logo', self)
